<?php


require_once 'Classes/PHPExcel.php';
require_once  'MapRowIterator.php';



class Excel2007MapReader
{
   protected $_objPHPExcel =null;
    
   public function Load($fileName)
   {
      try{
        $this->_objPHPExcel = PHPExcel_IOFactory::load($fileName);
         
      } catch (Exception $e) {
         echo 'Caught exception: ',  $e->getMessage(), "\n";
      }
      if(empty($this->_objPHPExcel))
      {
         return false;
      }
      $this->activeSheetIndex=0;
      return true;
   }

   protected $activeSheetIndex=0;

   public function prefetchHeader($sheetid)
   {
      $currentSheet= $this->_objPHPExcel->getSheet($sheetid);
      $roit=$currentSheet->getRowIterator();
      $row=$roit->current();
      $cellIterator = $row->getCellIterator();
      $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
      $result=array();
      foreach ($cellIterator as $cell) {
         
         if (!is_null($cell)) {
            $result[]=$cell->getCalculatedValue();
         }else
            $result[]="";
      }
     return    $result;   
   }

   public function getSheetCount()
   {
      return   count($this->_workSheetCollection);
   }

   public function getMapRowIterator()
   {
      $currentSheet= $this->_objPHPExcel->getSheet($this->activeSheetIndex);
      $r=new  MapRowIterator($currentSheet);
      return $r;
   }
}


?>